package com.team06.dao;


import com.team06.pojo.Gtls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.logging.Level;
import java.util.logging.Logger;

@Repository
public class GtlsDao {
    private static final Logger LOGGER = Logger.getLogger(GtlsDao.class.getName());
    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public GtlsDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertMessage(Gtls entity) {
        String sql = "INSERT INTO MSG_DFME_GTLS (" +
                "META_SNDR, META_RCVR, META_SEQN, META_DDTM, META_TYPE, META_STYP, " +
                "DFLT_FLID, DFLT_FFID, DFLT_FIDE, DFLT_FATT, GTNO, GATE_ID, CODE, GTAT, ESTR, EEND, RSTR, REND, BTSC) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        try {
            jdbcTemplate.update(sql,
                    entity.getMetaSnDR(),
                    entity.getMetaRCVR(),
                    entity.getMetaSEQN(),
                    entity.getMetaDDTM(),
                    entity.getMetaTYPE(),
                    entity.getMetaSTYP(),
                    entity.getDfltFLID(),
                    entity.getDfltFFID(),
                    entity.getDfltFIDE(),
                    entity.getDfltFATT(),
                    entity.getGtno(),
                    entity.getId(),
                    entity.getCode(),
                    entity.getGtat(),
                    entity.getEstr(),
                    entity.getEend(),
                    entity.getRstr(),
                    entity.getRend(),
                    entity.getBtsc()
            );
            LOGGER.info("数据插入成功（通过 Spring JDBC）");
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Failed to insert message into database", e);
            throw new RuntimeException("Failed to insert message into database", e);
        }
    }
}
